﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using ArkanoidX.Objects;

namespace ArkanoidX
{
    public class Introduction : Level
    {
        public class IntroBoard : BaseComponent
        {
            Introduction ContaininngLevel;
            Texture2D _texture;
            Rectangle _boundingRect;

            public bool LastEnterPressed = true;    // initiated from pressing enter

            public IntroBoard(Game game, Introduction containingLevel)
                : base(game)
            {
                _texture = game.Content.Load<Texture2D>("intro");
                ContaininngLevel = containingLevel;
                _boundingRect = ((MainGame)game).GameRectangle;
            }

            public override void Update(GameTime gameTime)
            {
                KeyboardState kbs = Keyboard.GetState();

                if (kbs.IsKeyDown(Keys.Enter))
                {
                    if (!LastEnterPressed)
                    {
                        ContaininngLevel.Finish();
                    }
                }

                LastEnterPressed = kbs.IsKeyDown(Keys.Enter);

                base.Update(gameTime);
            }

            public override void Draw(GameTime gameTime)
            {
                SpriteBatch sBatch = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));
                sBatch.Draw(_texture, _boundingRect, Color.White);

                base.Draw(gameTime);
            }
        }

        IntroBoard infoBoard;

        public Introduction(MainGame game)
            : base(game)
        {
            infoBoard = new IntroBoard(game, this);
        }

        public override void Start()
        {
            Game.ClearAllComponents();

            infoBoard.AddToLayer(Game.BaseLayer);

            LevelState = State.Running;
        }

        public override void Finish()
        {
            base.Finish();
            Game.BuildAndStartLevel(1);
        }
    }

    
}
